cd "C:\Users\kaish\Desktop\WHO and Covid Sources\R&R Response Submission\Conditional Acceptance\Coding" 
clear
use "C:\Users\kaish\Desktop\WHO and Covid Sources\R&R Response Submission\Conditional Acceptance\Coding\COVID 090820.dta"

## Figure 1: Adoption Curves (page 27)
twoway line World_school Date_num if Date_num<114, sort xline(71) xscale(range(0 115)) yaxis(1) ytitle("Number of policy adoptions") title("School Closures") name(world_school, replace) xtitle("Days")
graph export "Figure 1_School Trends.tif", replace
twoway line World_work Date_num if Date_num<114, sort xline(71) xscale(range(0 115)) name(world_work, replace) legend(off) title("Workplace Closures") xtitle("Days") ytitle("Number of policy adoptions") yscale(range(0 150)) ylabel(#3)
graph export "Figure 1_Work Trends.tif", replace
twoway line World_public Date_num if Date_num<114, sort xline(71) xscale(range(0 115)) name(world_public, replace) legend(off) title("Public Event Cancellation") xtitle("") ytitle("Number of policy adoptions") xtitle("Days")
graph export "Figure 1_Public Trends.tif", replace
twoway line World_domestic Date_num if Date_num<114, sort xline(71) xscale(range(0 115)) name(world_domestic, replace) legend(off) title("Domestic Travel Restrictions") xtitle("Days") ytitle("Number of policy adoptions") 
graph export "Figure 1_Domestic Trends.tif", replace
twoway line World_international Date_num if Date_num<114, sort xline(71) xscale(range(0 115)) name(world_international, replace) legend(off) ytitle("", axis(1)) title("International Travel Bans") xtitle("Days") ytitle("Number of policy adoptions") 
graph export "Figure 1_Intl Trends.tif", replace

## Figure 2 (Page 28)
	##Coefplot for WHO Pandemic Declaration Variable for Each of 5 Policies
		
		stset, clear
		stset tf, failure(des_school)
		quietly stcox World_school region_school World_casethou World_deaththou COVID_casesthou GHI_prime airmil pop_older65 WHO_pandemic5 US_school China_unesco FDI_US BRI_country V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 elections2020 v2x_freexp v2dlengage polyarchy_stddev v2x_polyarchy GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		estimates store School
			
		stset, clear
		stset tf, failure(des_work)
		quietly stcox World_work region_work World_casethou World_deaththou COVID_casesthou GHI_prime airmil pop_older65 WHO_pandemic5 US_work China_work FDI_US BRI_country V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 elections2020 v2x_freexp v2dlengage polyarchy_stddev v2x_polyarchy GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		estimates store Work
	
		stset, clear
		stset tf, failure(des_public)
		quietly stcox World_public region_public World_casethou World_deaththou COVID_casesthou GHI_prime airmil pop_older65 WHO_pandemic5 US_public China_public FDI_US BRI_country V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 elections2020 v2x_freexp v2dlengage polyarchy_stddev v2x_polyarchy GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		estimates store Public
		
		stset, clear
		stset tf, failure(des_domestic)
		quietly stcox World_domestic region_domestic World_casethou World_deaththou COVID_casesthou GHI_prime airmil pop_older65 WHO_pandemic5 US_domestic China_domestic FDI_US BRI_country V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 elections2020 v2x_freexp v2dlengage polyarchy_stddev v2x_polyarchy GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		estimates store Domestic_Travel
		
		stset, clear
		stset tf, failure(des_international)
		quietly stcox World_international region_international World_casethou World_deaththou COVID_casesthou GHI_prime airmil pop_older65 WHO_pandemic5 US_international China_international FDI_US BRI_country V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 elections2020 v2x_freexp v2dlengage polyarchy_stddev v2x_polyarchy GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		estimates store International_Travel
		
		coefplot (School, label("1 School Closure") msymbol(D)) (Work, label("2 Work Closure") msymbol(S)) (Public, label("3 Public Event Cancellation") msymbol(T)) (Domestic_Travel, label("4 Domestic Travel" "Restriction") msymbol(X)) (International_Travel, label("5 International Travel Ban")), /// 
		keep(WHO_pandemic5 ) xline(0) legend(position(7)) ylabel(1 "WHO Declaration")
		graph export "Figure 2_Coefplot.tif", replace

## Generate Statistical Analysis in Table 3 (Page 30)
	stset tf, failure(des_school)
		stcox WHO_pandemic5 World_school region_school World_casethou World_deaththou ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			US_school China_unesco FDI_US BRI_country ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		outreg2 using "table3.doc", replace label ctitle("School Closures") e(N_fail) drop(GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec )
		stset, clear
		stset tf, failure(des_work)
		stcox WHO_pandemic5 US_work China_work FDI_US BRI_country ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			World_work region_work World_casethou World_deaththou ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		outreg2 using "table3.doc", append label ctitle("Work Closures") e(N_fail) drop(GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec )
		stset, clear
		stset tf, failure(des_public)
		stcox WHO_pandemic5 US_public China_public FDI_US BRI_country ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			World_public region_public World_casethou World_deaththou ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		outreg2 using "table3.doc", append label ctitle("Public Event Closures") e(N_fail) drop(GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec )
		stset, clear
		stset tf, failure(des_domestic)
		stcox WHO_pandemic5 US_domestic China_domestic FDI_US BRI_country ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			World_domestic region_domestic World_casethou World_deaththou ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		outreg2 using "table3.doc", append label ctitle("Domestic Travel Ban") e(N_fail) drop(GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec )
		stset, clear
		stset tf, failure(des_international)
		stcox WHO_pandemic5 US_international China_international FDI_US BRI_country ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			World_international region_international World_casethou World_deaththou ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		outreg2 using "table3.doc", append label ctitle("International" "Travel Ban") e(N_fail) drop(GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec )	
		
## Figure 3 VIMP Score Bar Graph
	clear
	import delimited "C:\Users\kaish\Desktop\WHO and Covid Sources\R&R Response Submission\Conditional Acceptance\Coding\RSF_March2023_school.csv", case(preserve)
		rename Numberofpolicyadoptionsgloba Global_Policy_Adoptions
		rename Numberofpolicyadoptionsregionall Regional_Policy_Adoptions
		rename NumberofcasesofCOVID19intheregio Regional_Cases
		rename NumberofdeathsfromCOVID19inthere Regional_Deaths
		rename NumberofdeathsfromCOVID19inthewo Global_Deaths
		rename NumberofcasesofCOVID19intheworld Global_Cases
		rename NumberofcasesofCOVID19incountry Covid_Cases
		rename NumberofdeathsfromCOVID19incount Covid_Deaths
		rename Adoption5daysafterWHOdeclarespan WHO_Declaration
		rename Adoption5daysafterUSclosesschool US_Adoption
		
		graph hbar Global_Policy_Adoptions Regional_Policy_Adoptions WHO_Declaration Global_Deaths Global_Cases Regional_Cases Regional_Deaths Covid_Cases Covid_Deaths US_Adoption, ascat
		graph export "Figure 3_Random Forest VIMP_do.tif", replace
		
##Table 4: Grambsch Therneau Tests of Proportional Hazards Assumption for WHO Pandemic Declaration Variable
	clear
	use "C:\Users\kaish\Desktop\WHO and Covid Sources\R&R Response Submission\Conditional Acceptance\Coding\COVID 090820.dta"

	## Select Chi-2 statistics for WHO Pandemic Variable from Results

		## School Closures Policy
			stset, clear
			stset tf, failure(des_school)
			quietly stcox WHO_pandemic5 World_school region_school World_casethou World_deaththou ///
				COVID_casesthou GHI_prime airmil pop_older65 ///
				US_school China_unesco FDI_US BRI_country ///
				V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
				v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
				GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
			
			estat phtest, detail

		## Workplace Closures Policy
			stset, clear
			stset tf, failure(des_work)
			quietly stcox WHO_pandemic5 US_work China_work FDI_US BRI_country ///
				COVID_casesthou GHI_prime airmil pop_older65 ///
				World_work region_work World_casethou World_deaththou ///
				V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
				v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
				GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr

			estat phtest, detail
			
		## Public Events Cancellation
			stset, clear
			stset tf, failure(des_public)
			quietly stcox WHO_pandemic5 US_public China_public FDI_US BRI_country ///
				COVID_casesthou GHI_prime airmil pop_older65 ///
				World_public region_public World_casethou World_deaththou ///
				V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
				v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
				GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
			
			estat phtest, detail
						
		## Domestic Travel Restriction
			stset, clear
			stset tf, failure(des_domestic)
			quietly stcox WHO_pandemic5 US_domestic China_domestic FDI_US BRI_country ///
				COVID_casesthou GHI_prime airmil pop_older65 ///
				World_domestic region_domestic World_casethou World_deaththou ///
				V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
				v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
				GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohrstset, clear
			
			estat phtest, detail
	
		## International Travel Ban
			stset tf, failure(des_international)
			quietly stcox WHO_pandemic5 US_international China_international FDI_US BRI_country ///
				COVID_casesthou GHI_prime airmil pop_older65 ///
				World_international region_international World_casethou World_deaththou ///
				V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
				v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
				GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
			
			estat phtest, detail
			
##Figure 4: Deviance Residuals over time and by region for School Closures(page 37)
		stset, clear
		stset tf, failure(des_school)
		quietly stcox WHO_pandemic5 World_school region_school World_casethou World_deaththou ///
			COVID_casesthou GHI_prime airmil pop_older65 ///
			US_school China_unesco FDI_US BRI_country ///
			V4_Bin V8_Bin v2exl_legitideol v2exl_legitideolcr_0 v2exl_legitideolcr_1 v2exl_legitideolcr_2 v2exl_legitideolcr_3 v2exl_legitideolcr_4 ///
			v2x_polyarchy elections2020 v2x_freexp v2dlengage polyarchy_stddev ///
			GDPmil HDI areamil popmil v2xel_locelec v2xel_regelec women_in_parliament, nohr
		predict dev, deviance	

		lowess dev tf if tf<125, title("School Closure" "Deviance Residuals Over Time")
		graph export "Figure 4_School Closure Deviance over Time.tif", replace
		lowess dev region, title("School Closure" "Deviance Residuals Over Region")
		graph export "Figure 4_School Closure Deviance over Region.tif", replace

##Coding for Appendices Available on Request
